package net.mysoft.framework.util;

import java.util.Date;

public class TimeUtil {
    public static String format(long ms) {//将毫秒数换算成x天x时x分x秒x毫秒
    	int ss = 1000;
    	int mi = ss * 60;
    	int hh = mi * 60;
    	int dd = hh * 24;

    	long day = ms / dd;
    	long hour = (ms - day * dd) / hh;
    	long minute = (ms - day * dd - hour * hh) / mi;
    	long second = (ms - day * dd - hour * hh - minute * mi) / ss;
    	long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

    	String strDay = day < 10 ? "0" + day : "" + day;
    	String strHour = hour < 10 ? "0" + hour : "" + hour;
    	String strMinute = minute < 10 ? "0" + minute : "" + minute;
    	String strSecond = second < 10 ? "0" + second : "" + second;
    	String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;
    	strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;
    	//strDay + "天" + strHour + "小时" + strMinute + "分钟" + strSecond + "秒" + strMilliSecond;
    	return strDay + "天" + strHour + "小时" + strMinute + "分";
    }
    public static String format(Date startTime,Date endTime) {
    	if(endTime==null){
    		endTime = new Date();
    	}
    	long l = endTime.getTime()-startTime.getTime();
    	return format(l);
    }
    public static void main(String[] args){
    	Date d = new Date();
    	
    	for(long x=0;x<100000l;x++){
    		long y = 2*x;
    	}
    	//System.out.println(format(d,null));
    }
    
}
